package com.huike.web.controller;


import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;

/**
 * @author BaiYang
 * @time 2022/9/27
 */
public class FutureTest {

    public static void main(String[] args) {
        CompletableFuture<Integer> task1 = CompletableFuture.supplyAsync(() -> {
            System.out.println("线程1");
            try {
                System.out.println("等我睡一会！");
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("线程1执行完成");
            return 1;
        });
        CompletableFuture<Integer> task2 = CompletableFuture.supplyAsync(new Supplier<Integer>() {
                    @Override
                    public Integer get() {
                        System.out.println("新线程2");
                        return 2;
                    }
                });
        CompletableFuture.allOf(task1, task2).join();
//        CompletableFuture.allOf(task1, task2)
        System.out.println("主线程跑了");

    }
}
